#pragma once

#include <functional>
#include <mutex>
#include <condition_variable>
#include <string>

#include "noncopyable.h"
#include "Thread.h"


class EventLoop;
// 也不是继承
class EventLoopThread : noncopyable
{
public: 
    /*输入参数是线程绑定的EventLoop*/
    using ThreadInitCallback = std::function<void(EventLoop *)>;


    EventLoopThread(const ThreadInitCallback &cb = ThreadInitCallback(),
                    const std::string &name = std::string());
    ~EventLoopThread();
    /*?*/
    EventLoop *startLoop();
private:
    void threadFunc();

    EventLoop *loop_;
    bool exiting_;
    Thread thread_;
    std::mutex mutex_;             // 互斥锁
    std::condition_variable cond_; // 条件变量
    ThreadInitCallback callback_;
};